<!doctype html>
<html lang="en">
<head>
    <!-- Required meta tags -->
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <title>Hello, Bootstrap Table!</title>
    <link rel="stylesheet" href="../css/fontawesome/css/font-awesome.css">
    <link rel="stylesheet" href="../css/bootstrap-table.css">
    <link rel="stylesheet" href="../css/bootstrap.min.css">
    <script src="../js/jquery-3.4.1.js"></script>
    <script src="../js/bootstrap.min.js"></script>
    <script src="../js/bootstrap-table.min.js"></script>
</head>
<body>
<div class="toolbar">
    <button id="load" class="btn btn-secondary">Load 10000 Rows</button>
    <button id="append" class="btn btn-secondary">Append 10000 Rows</button>
    Total rows: <span id="total"></span>
</div>

<table id="table"
       data-toolbar=".toolbar"
       data-height="400"
       data-virtual-scroll="true"
       data-show-columns="true">
    <thead>
    <tr>
        <th data-field="id">ID</th>
        <th data-field="name">Item Name</th>
        <th data-field="price">Item Price</th>
    </tr>
    </thead>
</table>

<script>
  var $table = $('#table')
  var total = 0

  function getData(number, isAppend) {
    if (!isAppend) {
      total = 0
    }
    var data = []
    for (var i = total; i < total + number; i++) {
      data.push({
        'id': i,
        'name': 'Item ' + i,
        'price': '$' + i
      })
    }
    if (isAppend) {
      total += number
    } else {
      total = number
    }
    $('#total').text(total)
    return data
  }

  $(function() {
    $table.bootstrapTable({data: getData(20)})

    $('#load').click(function () {
      $table.bootstrapTable('load', getData(10000))
    })

    $('#append').click(function () {
      $table.bootstrapTable('append', getData(10000, true))
    })
  })
</script>
</body>
</html>
